﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class backmanage_API_A_Spreadip : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        string returnStr = string.Empty;
        string editType = Request.Form["edit"];
        switch (editType)
        {
            case "add":
                {
                    returnStr = SpreadipAdd();
                    break;
                }
            case "list":
                {
                    returnStr = SpreadipList();
                    break;
                }
            default: break;
        }
        Response.Write(returnStr);
    }
    protected string SpreadipAdd()
    {
        MODEL.SpreadIP model = new MODEL.SpreadIP();
        BLL.Spreadip bll = new BLL.Spreadip();
        string returnStr = string.Empty;
        model.SIPNAME = Request.Form["n"];
        model.SIPNUMBER = Request.Form["i"];
        model.SCONTACT = Request.Form["c"];
        model.STEL = Request.Form["t"];
        model.SPROVINCE = Request.Form["p"];
        model.SCITY = Request.Form["ct"];
        model.SDISTRICT = Request.Form["d"];
        model.SCOUNTY = Request.Form["cy"];
        model.SADDRESS = Request.Form["a"];
        model.SSPREADID = Request.Form["s"];
        bool flag = bll.SpreadipAdd(model);
        if (flag)
        {
            returnStr = "{\"err\":\"1\"}";
        }
        else
        {
            returnStr = "{\"err\":\"0\"}";
        }
        return returnStr;
    }
    protected string SpreadipList()
    {
        BLL.Spreadip bll = new BLL.Spreadip();
        StringBuilder htmlStr = new StringBuilder();
        DataTable dt = bll.SpreadipList().Tables[0];
        foreach (DataRow dr in dt.Rows)
        {
            htmlStr.Append("<tr id=\"" + dr["Sid"].ToString() + "\">");
            htmlStr.Append("<td>" + dr["Sipname"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Scontact"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Stel"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Sipnumber"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Sprovince"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Scity"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Sdistrict"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Scounty"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Saddress"].ToString() + "</td>");
            htmlStr.Append("<td>" + dr["Sspreadid"].ToString() + "</td>");
            htmlStr.Append("<td><span class=\"update\">修改</span></td>");
            htmlStr.Append("</tr>");
        }
        return htmlStr.ToString();
    }
}
